package main

import (
	"fmt"
	"net"
	"time"
)

func main() {
	lis, err := net.Listen("tcp", ":8080")
	if err != nil {
		fmt.Println("监听错误:", err)
		return
	}
	for {
		conn, err := lis.Accept()
		if err != nil {
			fmt.Println("建立连接异常:", err)
			continue
		}
		go ReadConn1(conn)
	}
}

func ReadConn1(conn net.Conn) {
	for {
		bytes := make([]byte, 1024)

		conn.SetReadDeadline(time.Now().Add(1 * time.Second))
		n, err := conn.Read(bytes)
		if err != nil {
			fmt.Println("服务器端读取是失败:", err)
			return
		}
		fmt.Println("服务器端读取到数据:", string(bytes[:n]))
	}
}
